package com.baidu.location;

import android.location.Location;
import android.util.Log;
import java.io.File;
import java.io.RandomAccessFile;
import java.security.MessageDigest;
import java.util.Calendar;

final class ak
{
  public static int A;
  public static int B;
  public static int C;
  public static int D;
  public static float E;
  public static float F;
  public static float G;
  public static float H;
  public static int I;
  public static float J;
  public static int K;
  public static float L;
  public static float M;
  public static float N;
  public static int O;
  public static int P;
  public static boolean Q;
  public static boolean R;
  public static int S;
  public static int T;
  public static int U;
  public static long V;
  public static long W;
  public static long X;
  public static int Y;
  public static boolean Z;
  public static boolean a = false;
  public static boolean aa;
  public static boolean ab;
  public static boolean ac;
  public static boolean ad;
  public static boolean ae;
  public static float af;
  public static float ag;
  public static int ah;
  public static int ai;
  public static int aj;
  public static String ak;
  public static String al;
  public static int am;
  public static int an;
  public static int ao;
  private static String ap;
  private static String aq;
  private static boolean ar;
  private static boolean as;
  private static String at;
  private static Process au;
  private static final String av;
  public static boolean b = false;
  public static boolean c = false;
  public static int d = 0;
  public static String e;
  public static String f;
  public static String g;
  public static String h;
  public static boolean i;
  public static boolean j;
  public static int k;
  public static double l;
  public static double m;
  public static double n;
  public static double o;
  public static int p;
  public static byte[] q;
  public static boolean r;
  public static int s;
  public static float t;
  public static float u;
  public static float v;
  public static float w;
  public static int x;
  public static int y;
  public static int z;

  static
  {
    ap = "baidu_location_service";
    aq = "http://loc.map.baidu.com/sdk.php";
    e = "http://loc.map.baidu.com/sdk_ep.php";
    ar = false;
    as = true;
    at = "[baidu_location_service]";
    au = null;
    f = null;
    g = "no";
    h = "gcj02";
    i = true;
    j = true;
    k = 3;
    l = 0.0D;
    m = 0.0D;
    n = 0.0D;
    o = 0.0D;
    p = 0;
    q = null;
    r = false;
    s = 0;
    t = 1.1F;
    u = 2.2F;
    v = 2.3F;
    w = 3.8F;
    x = 3;
    y = 10;
    z = 2;
    A = 7;
    B = 20;
    C = 70;
    D = 120;
    E = 2.0F;
    F = 10.0F;
    G = 50.0F;
    H = 200.0F;
    I = 16;
    J = 0.9F;
    K = 5000;
    L = 0.5F;
    M = 0.0F;
    N = 0.1F;
    O = 30;
    P = 100;
    Q = true;
    R = true;
    S = 20;
    T = 300;
    U = 1000;
    V = 1200000L;
    W = 20L;
    X = 300000L;
    Y = 0;
    Z = true;
    aa = true;
    ab = false;
    ac = true;
    ad = true;
    ae = true;
    af = 6.0F;
    ag = 10.0F;
    ah = 60;
    ai = 70;
    aj = 6;
    av = f.a + "/con.dat";
    ak = null;
    al = null;
    am = -1;
    an = -1;
    ao = 0;
  }

  static int a(String paramString1, String paramString2, String paramString3)
  {
    int i1;
    if ((paramString1 == null) || (paramString1.equals("")));
    do
    {
      int i2;
      do
      {
        do
        {
          return -2147483648;
          i1 = paramString1.indexOf(paramString2);
        }
        while (i1 == -1);
        i1 += paramString2.length();
        i2 = paramString1.indexOf(paramString3, i1);
      }
      while (i2 == -1);
      paramString1 = paramString1.substring(i1, i2);
    }
    while ((paramString1 == null) || (paramString1.equals("")));
    try
    {
      i1 = Integer.parseInt(paramString1);
      return i1;
    }
    catch (NumberFormatException paramString1)
    {
      paramString1.printStackTrace();
    }
    return -2147483648;
  }

  static String a()
  {
    Calendar localCalendar = Calendar.getInstance();
    int i1 = localCalendar.get(5);
    return String.format("%d-%d-%d %d:%d:%d", new Object[] { Integer.valueOf(localCalendar.get(1)), Integer.valueOf(localCalendar.get(2) + 1), Integer.valueOf(i1), Integer.valueOf(localCalendar.get(11)), Integer.valueOf(localCalendar.get(12)), Integer.valueOf(localCalendar.get(13)) });
  }

  public static String a(u paramu, z paramz, Location paramLocation, String paramString, int paramInt)
  {
    StringBuffer localStringBuffer = new StringBuffer();
    if (paramu != null)
    {
      str = paramu.toString();
      if (str != null)
        localStringBuffer.append(str);
    }
    if (paramz != null)
    {
      if (paramInt != 0)
        break label255;
      str = paramz.b();
      if (str != null)
        localStringBuffer.append(str);
    }
    if (paramLocation != null)
    {
      if ((d == 0) || (paramInt == 0))
        break label264;
      str = n.b(paramLocation);
      if (str != null)
        localStringBuffer.append(str);
    }
    boolean bool = false;
    if (paramInt == 0)
      bool = true;
    String str = t.a(bool);
    if (str != null)
      localStringBuffer.append(str);
    if (paramString != null)
      localStringBuffer.append(paramString);
    if (paramu != null)
    {
      paramu = paramu.d();
      if ((paramu != null) && (paramu.length() + localStringBuffer.length() < 750))
        localStringBuffer.append(paramu);
    }
    paramu = localStringBuffer.toString();
    if ((paramLocation != null) && (paramz != null))
    {
      try
      {
        float f1;
        int i1;
        int i2;
        while (true)
        {
          while (true)
          {
            f1 = paramLocation.getSpeed();
            paramInt = d;
            i1 = paramz.e();
            i2 = paramz.a();
            bool = paramz.f();
            if ((f1 >= af) || ((paramInt != 1) && (paramInt != 0)) || ((i1 >= ah) && (bool != true)))
              break label273;
            k = 1;
            return paramu;
            label255: str = paramz.c();
          }
          label264: str = n.a(paramLocation);
        }
        label273: if ((f1 >= ag) || ((paramInt != 1) && (paramInt != 0) && (paramInt != 3)) || ((i1 >= ai) && (i2 <= aj)))
          break label328;
        k = 2;
        return paramu;
      }
      catch (Exception paramz)
      {
        k = 3;
        return paramu;
      }
      label328: k = 3;
      return paramu;
    }
    k = 3;
    return paramu;
  }

  static String a(String paramString1, String paramString2, String paramString3, double paramDouble)
  {
    int i1;
    int i2;
    if ((paramString1 == null) || (paramString1.equals("")));
    do
    {
      do
      {
        return null;
        i1 = paramString1.indexOf(paramString2);
      }
      while (i1 == -1);
      i1 += paramString2.length();
      i2 = paramString1.indexOf(paramString3, i1);
    }
    while (i2 == -1);
    paramString2 = paramString1.substring(0, i1);
    paramString1 = paramString1.substring(i2);
    paramString3 = String.format("%.7f", new Object[] { Double.valueOf(paramDouble) });
    return paramString2 + paramString3 + paramString1;
  }

  public static String a(byte[] paramArrayOfByte)
  {
    try
    {
      Object localObject = MessageDigest.getInstance("MD5");
      ((MessageDigest)localObject).reset();
      ((MessageDigest)localObject).update(paramArrayOfByte);
      paramArrayOfByte = ((MessageDigest)localObject).digest();
      localObject = new StringBuilder();
      int i2 = paramArrayOfByte.length;
      int i1 = 0;
      while (i1 < i2)
      {
        String str = Integer.toHexString(paramArrayOfByte[i1] & 0xFF).toUpperCase();
        if (str.length() == 1)
          ((StringBuilder)localObject).append("0");
        ((StringBuilder)localObject).append(str).append("");
        i1 += 1;
      }
      paramArrayOfByte = ((StringBuilder)localObject).toString();
      return paramArrayOfByte;
    }
    catch (java.security.NoSuchAlgorithmException paramArrayOfByte)
    {
      throw new RuntimeException(paramArrayOfByte);
    }
  }

  public static void a(int paramInt)
  {
    int i2 = 1;
    if ((paramInt & 0x1) == 1)
    {
      i1 = 1;
      Z = i1;
      if ((paramInt & 0x2) != 2)
        break label143;
      i1 = 1;
      aa = i1;
      if ((paramInt & 0x4) != 4)
        break label148;
      i1 = 1;
      ab = i1;
      if ((paramInt & 0x8) != 8)
        break label153;
      i1 = 1;
      ac = i1;
      if ((paramInt & 0x10000) != 65536)
        break label158;
      i1 = 1;
      ad = i1;
      if ((paramInt & 0x20000) != 131072)
        break label163;
    }
    label143: label148: label153: label158: label163: for (int i1 = i2; ; i1 = 0)
      while (true)
      {
        while (true)
        {
          while (true)
          {
            while (true)
            {
              while (true)
              {
                ae = i1;
                new StringBuilder("A1~C3:").append(Z).append(aa).append(ab).append(ac).append(ad).append(ae);
                return;
                i1 = 0;
              }
              i1 = 0;
            }
            i1 = 0;
          }
          i1 = 0;
        }
        i1 = 0;
      }
  }

  public static void a(String paramString1, String paramString2)
  {
    if (!(ar))
      return;
    Log.d(paramString1, paramString2);
  }

  public static boolean a(String paramString)
  {
    int i1 = a(paramString, "error\":\"", "\"");
    return ((i1 <= 100) || (i1 >= 200));
  }

  static float b(String paramString1, String paramString2, String paramString3)
  {
    if ((paramString1 == null) || (paramString1.equals("")));
    do
    {
      int i1;
      int i2;
      do
      {
        do
        {
          return 1.4E-45F;
          i1 = paramString1.indexOf(paramString2);
        }
        while (i1 == -1);
        i1 += paramString2.length();
        i2 = paramString1.indexOf(paramString3, i1);
      }
      while (i2 == -1);
      paramString1 = paramString1.substring(i1, i2);
    }
    while ((paramString1 == null) || (paramString1.equals("")));
    try
    {
      float f1 = Float.parseFloat(paramString1);
      return f1;
    }
    catch (NumberFormatException paramString1)
    {
      paramString1.printStackTrace();
    }
    return 1.4E-45F;
  }

  public static void b()
  {
    int i1 = 0;
    try
    {
      Object localObject = new File(av);
      if (((File)localObject).exists())
      {
        localObject = new RandomAccessFile((File)localObject, "rw");
        ((RandomAccessFile)localObject).seek(4L);
        int i2 = ((RandomAccessFile)localObject).readInt();
        int i3 = ((RandomAccessFile)localObject).readInt();
        ((RandomAccessFile)localObject).seek(128L);
        byte[] arrayOfByte = new byte[i2];
        if (i1 < i3)
        {
          ((RandomAccessFile)localObject).seek(i2 * i1 + 128);
          int i4 = ((RandomAccessFile)localObject).readInt();
          if ((i4 <= 0) || (i4 >= i2))
            break label193;
          ((RandomAccessFile)localObject).read(arrayOfByte, 0, i4);
          if (arrayOfByte[(i4 - 1)] != 0)
            break label193;
          String str = new String(arrayOfByte, 0, i4 - 1);
          if (!(str.equals(ak)))
            break label193;
          am = ((RandomAccessFile)localObject).readInt();
          ao = i1;
          new StringBuilder().append(str).append(am);
        }
        if (i1 == i3)
          ao = i3;
        ((RandomAccessFile)localObject).close();
      }
      return;
      label193: i1 += 1;
    }
    catch (Exception localException)
    {
    }
  }

  public static void b(int paramInt)
  {
    File localFile = new File(av);
    if (!(localFile.exists()));
    try
    {
      Object localObject1;
      Object localObject2 = new File(av);
      if (!(((File)localObject2).exists()))
      {
        localObject1 = new File(f.a);
        if (!(((File)localObject1).exists()))
          ((File)localObject1).mkdirs();
        localObject1 = localObject2;
        if (!(((File)localObject2).createNewFile()))
          localObject1 = null;
        localObject1 = new RandomAccessFile((File)localObject1, "rw");
        ((RandomAccessFile)localObject1).seek(0L);
        ((RandomAccessFile)localObject1).writeInt(0);
        ((RandomAccessFile)localObject1).writeInt(128);
        ((RandomAccessFile)localObject1).writeInt(0);
        ((RandomAccessFile)localObject1).close();
      }
      try
      {
        localObject1 = new RandomAccessFile(localFile, "rw");
        ((RandomAccessFile)localObject1).seek(4L);
        int i1 = ((RandomAccessFile)localObject1).readInt();
        int i2 = ((RandomAccessFile)localObject1).readInt();
        ((RandomAccessFile)localObject1).seek(i1 * ao + 128);
        localObject2 = ak + '\0'.getBytes();
        ((RandomAccessFile)localObject1).writeInt(localObject2.length);
        ((RandomAccessFile)localObject1).write(localObject2, 0, localObject2.length);
        ((RandomAccessFile)localObject1).writeInt(paramInt);
        if (i2 == ao)
        {
          ((RandomAccessFile)localObject1).seek(8L);
          ((RandomAccessFile)localObject1).writeInt(i2 + 1);
        }
        ((RandomAccessFile)localObject1).close();
        return;
      }
      catch (Exception localException1)
      {
        return;
      }
    }
    catch (Exception localException2)
    {
    }
  }

  static double c(String paramString1, String paramString2, String paramString3)
  {
    if ((paramString1 == null) || (paramString1.equals("")));
    do
    {
      int i1;
      int i2;
      do
      {
        do
        {
          return 4.9E-324D;
          i1 = paramString1.indexOf(paramString2);
        }
        while (i1 == -1);
        i1 += paramString2.length();
        i2 = paramString1.indexOf(paramString3, i1);
      }
      while (i2 == -1);
      paramString1 = paramString1.substring(i1, i2);
    }
    while ((paramString1 == null) || (paramString1.equals("")));
    try
    {
      double d1 = Double.parseDouble(paramString1);
      return d1;
    }
    catch (NumberFormatException paramString1)
    {
      paramString1.printStackTrace();
    }
    return 4.9E-324D;
  }

  public static void c()
  {
    if (!(ar))
      return;
    try
    {
      File localFile;
      do
      {
        if (au != null)
        {
          au.destroy();
          au = null;
        }
        localFile = new File(f.a);
      }
      while (localFile.exists());
      localFile.mkdirs();
      return;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }

  public static void d()
  {
    if (au != null);
    try
    {
      au.destroy();
      return;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }

  public static void e()
  {
  }

  public static String f()
  {
    return aq;
  }
}